package com.nine.aop.controller;

import com.nine.aop.domain.User;
import com.nine.aop.properties.TestYmlProperties;
import com.nine.aop.result.R;
import com.nine.aop.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {

    // 配合 @RequiredArgsConstructor 注入 UserService
    private final UserService userService;

    private final TestYmlProperties testYmlProperties;

    @Value("${test.name}")
    private String name;

    @GetMapping("{id}")
    public R testUser(@PathVariable String id) {

        log.info("properties 读取custom.yml的数据，test.name={}", testYmlProperties.getName());
        log.info("@Value 读取custom.yml的数据，test.name={}", testYmlProperties.getName());

        User user = userService.findUserById(id);
        return R.ok(user);
    }

}
